package com.sangananitsolution.database;

import java.util.ArrayList;

import com.sangananitsolution.database.DatabaseTables.UserInfo;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class UserInfoCRUD {

	static DatabaseHelper databaseHelper = null;
	Context contextvalue;

	public UserInfoCRUD(Context context) {
	

		databaseHelper = new DatabaseHelper(context);
		contextvalue = context;
	}

	public void insert(String emailadress, String firstName, String lastName,
			String phoneNumber, String country, String longitute,
			String latitute, String userImage, String facebookId,
			String isvaliduser, String hashCode, String statusmsg, String userId) {

		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper != null) {
			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getWritableDatabase();
			ContentValues content = new ContentValues();
			content.put(UserInfo.FIRST_NAME, firstName);
			content.put(UserInfo.LAST_NAME, lastName);
			content.put(UserInfo.EMAIL, emailadress);
			content.put(UserInfo.PHONE, phoneNumber);
			content.put(UserInfo.Country, country);
			content.put(UserInfo.FacebookId, facebookId);
			content.put(UserInfo.HashCode, hashCode);
			content.put(UserInfo.IsValidUser, isvaliduser);
			content.put(UserInfo.Latitude, latitute);
			content.put(UserInfo.Longitude, longitute);
			content.put(UserInfo.StatusMessage, statusmsg);
			content.put(UserInfo.UserId, userId);
			content.put(UserInfo.UserImage, userImage);
			sqLiteDatabase.insert(UserInfo.TABLE_NAME, null, content);

		}
		// Insert the data from the content values here

	}

	public ArrayList<String> getAllData() {
		// Fetching the sqLiteDatabase in the readable mode
		ArrayList<String> arrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			Cursor cursor = sqLiteDatabase.rawQuery(
					"select max(_uID) from userinfo;", null);

			int sum = 0;
			if (cursor.moveToFirst()) {
				sum = cursor.getInt(0);
			}

			String[] column = { UserInfo.FIRST_NAME, UserInfo.LAST_NAME,
					UserInfo.EMAIL, UserInfo.PHONE, UserInfo.Country,
					UserInfo.Longitude, UserInfo.Latitude, UserInfo.UserImage,
					UserInfo.FacebookId, UserInfo.IsValidUser, UserInfo.HashCode,
					UserInfo.StatusMessage, UserInfo.UserId };
			Cursor cursorvalue = sqLiteDatabase.query(UserInfo.TABLE_NAME,
					column, UserInfo.UID + "= ' " + sum + "	' ", null, null,
					null, null);

			if (cursorvalue.moveToFirst())

				do {
					arrayList.add(cursorvalue.getString(cursorvalue
							.getColumnIndex(UserInfo.FIRST_NAME)));
					arrayList.add(cursorvalue.getString(cursorvalue
							.getColumnIndex(UserInfo.LAST_NAME)));
					arrayList.add(cursorvalue.getString(cursorvalue
							.getColumnIndex(UserInfo.EMAIL)));
					arrayList.add(cursorvalue.getString(cursorvalue
							.getColumnIndex(UserInfo.PHONE)));
					arrayList.add(cursorvalue.getString(cursorvalue
							.getColumnIndex(UserInfo.Country)));
					  arrayList.add(cursorvalue.getString(cursorvalue
					  .getColumnIndex(UserInfo.Longitude)));
					 arrayList.add(cursorvalue.getString(cursorvalue
					  .getColumnIndex(UserInfo.Latitude)));
					  arrayList.add(cursorvalue.getString(cursorvalue
					  .getColumnIndex(UserInfo.UserImage)));
					  arrayList.add(cursorvalue.getString(cursorvalue
					  .getColumnIndex(UserInfo.FacebookId)));
					  arrayList.add(cursorvalue.getString(cursorvalue
					  .getColumnIndex(UserInfo.IsValidUser)));
					  arrayList.add(cursorvalue.getString(cursorvalue
					  .getColumnIndex(UserInfo.HashCode)));
					  arrayList.add(cursorvalue.getString(cursorvalue
					  .getColumnIndex(UserInfo.StatusMessage)));
					  arrayList.add(cursorvalue.getString(cursorvalue
					  .getColumnIndex(UserInfo.UserId)));
					 
				} while (cursorvalue.moveToNext());

		}
		return arrayList;
	}

	public void getSpecificData(String selectionArgs) {
		// Fetching the sqLiteDatabase in the readable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getReadableDatabase();

	}

	public void updateAllData(ContentValues contentValues) {
		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();

	}

	public void updateSpecificData(String selectionArgs) {
		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();

	}

	public void deleteAllData() {
		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();

	}

	public void deleteSpecificData(String selectionArgs) {
		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();

	}

}